package com.xiweicheng.test.springboot.mutil.ds;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import lombok.extern.slf4j.Slf4j;

@ServletComponentScan
@SpringBootApplication
@RestController
@Slf4j
public class Application {

    @Autowired
    UserRepository userRepository;

    public static void main(String[] args) {

        SpringApplication.run(Application.class, args);
    }

    @PostMapping("create")
    @Transactional(value="transactionManager")
    public User create(@RequestBody User user) {

        log.debug("create user: {}", user);
        return userRepository.saveAndFlush(user);
    }

}
